package com.atguigu.cdc;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.hadoop.yarn.client.api.impl.TimelineConnector;

public class FlinkCDC02_SQL {
    public static void main(String[] args) {
        // TODO: 1. 基本环境准备
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        StreamTableEnvironment tableEnvironment = StreamTableEnvironment.create(env);
        // TODO: 2. 创建动态表
        tableEnvironment.executeSql("CREATE TABLE user_info (" +
                " id INT NOT NULL," +
                " name STRING," +
                " age INT" +
                ") WITH (" +
                " 'connector' = 'mysql-cdc'," +
                " 'hostname' = 'hadoop102'," +
                " 'port' = '3306'," +
                " 'username' = 'root'," +
                " 'password' = '000000'," +
                " 'database-name' = 'gmall2021_realtime'," +
                " 'table-name' = 't_user'" +
                ")");
        // TODO: 从表中查询数据
        tableEnvironment.executeSql("select * from user_info").print();


    }
}
